package com.zuocheng.librarycar;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.lifecycle.LifecycleOwner;

import com.alibaba.fastjson.JSONObject;
import com.stx.xhb.xbanner.XBanner;
import com.youth.banner.Banner;
import com.youth.banner.indicator.CircleIndicator;

public class CarDetailActivity extends Activity {
    public CarBean carBeanItem;

    public static void start(Context context ,String carBean) {
        Intent intent = new Intent(context,CarDetailActivity.class);
        intent.putExtra("carBean",carBean);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);

    }
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_car_detail);

        String carBeanJson = getIntent().getStringExtra("carBean");
        carBeanItem = JSONObject.parseObject(carBeanJson,CarBean.class);

        System.out.println("-------"+carBeanJson);
        initTitle();
        setAndroidNativeLightStatusBar(this,true);

        Banner banner = findViewById(R.id.banner_ad);
        BnanerImageAdapter adapter = new BnanerImageAdapter(DataBean.getTestData2());

        banner.setAdapter(adapter)
//              .setCurrentItem(0,false)
//              .addBannerLifecycleObserver(this)//添加生命周期观察者
                .setIndicator(new CircleIndicator(this))//设置指示器
                .setOnBannerListener((data, position) -> {
                    System.out.println("=========");
//                    Snackbar.make(banner, ((DataBean) data).title, Snackbar.LENGTH_SHORT).show();
//                    LogUtils.d("position：" + position);
                });

        reloadBanner();
        reloadUI();

    }
    public void reloadBanner(){
        TextView tv_name = findViewById(R.id.tv_name);
        TextView tv_register_time = findViewById(R.id.tv_register_time);
        TextView tv_kilometre = findViewById(R.id.tv_kilometre);
        TextView tv_car_type = findViewById(R.id.tv_car_type);
        TextView tv_price = findViewById(R.id.tv_price);
        tv_name.setText(carBeanItem.carBrand + carBeanItem.carModel + carBeanItem.color);
        tv_register_time.setText(carBeanItem.buyDate);
        tv_kilometre.setText(carBeanItem.buyDate);
        tv_car_type.setText(carBeanItem.kilometreNumber +"km");
        tv_price.setText(carBeanItem.statusName);
    }


    public void reloadUI(){
        TextView textView_0 = findViewById(R.id.tv_brand0);
        TextView textView_1 = findViewById(R.id.tv_brand1);
        TextView textView_2 = findViewById(R.id.tv_brand2);
        TextView textView_3 = findViewById(R.id.tv_brand3);
        TextView textView_4 = findViewById(R.id.tv_brand4);
        TextView textView_5 = findViewById(R.id.tv_brand5);
        TextView textView_6 = findViewById(R.id.tv_brand6);
        TextView textView_7 = findViewById(R.id.tv_brand7);
        TextView textView_8 = findViewById(R.id.tv_brand8);
        TextView textView_9 = findViewById(R.id.tv_brand9);
        TextView textView_10 = findViewById(R.id.tv_brand10);
        TextView textView_11 = findViewById(R.id.tv_brand11);
        TextView textView_12 = findViewById(R.id.tv_brand12);
        TextView textView_13 = findViewById(R.id.tv_brand13);

        textView_0.setText(carBeanItem.buyDate);
        textView_1.setText(carBeanItem.buyPrice);
        textView_2.setText(carBeanItem.carBrand);
        textView_3.setText(carBeanItem.carModel);
        textView_4.setText(carBeanItem.color);
        textView_5.setText(carBeanItem.outputVolume);
        textView_6.setText(carBeanItem.vinNo);
        textView_7.setText(carBeanItem.registrDate);

        textView_8.setText(carBeanItem.settleAddress);
        textView_9.setText(carBeanItem.carExaminationDate);
        textView_10.setText(carBeanItem.kilometreNumber);
        textView_11.setText(carBeanItem.contributorName);
        textView_12.setText(carBeanItem.addressName);
        textView_13.setText(carBeanItem.inputUserName);

    }

    public void initTitle() {
        OverAllTitleBar rlTitle = findViewById(R.id.rl_title);
        rlTitle.tvTitle.setText("车辆详情");
        rlTitle.ivBack.setVisibility(View.VISIBLE);
        rlTitle.ivBack.setOnClickListener(v -> {
            finish();
        });
    }
    //设置状态栏字体颜色
    private static void setAndroidNativeLightStatusBar(Activity activity, boolean dark) {
        View decor = activity.getWindow().getDecorView();
        if (dark) {
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }
    }
}
